home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 310 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.7 KB

  1. From: clamage@eng.sun.com (Steve Clamage)
  2. Message-ID: <4f8o3i$hb6@engnews1.Eng.Sun.COM>
  3. X-Original-Date: 6 Feb 1996 23:26:42 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 07 Feb 96 01:50:16 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Forward declaration of a sub-class?
  9. Organization: Sun Microsystems Inc.
  10. References: <199602062218.RAA08320@pythagoras.csc.ncsu.edu>
  11. Reply-To: clamage@eng.sun.com
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMRgFoeEDnX0m9pzZAQGkmgF+I/GbO4LK3Hd+wJfZ0A4Tm9XoTUDGjCny
  14.     r9RwFGB/sBUpjlXVPuPnXBQDFvLgfPw6
  15.     =5LSM
  16.  
  17. In article RAA08320@pythagoras.csc.ncsu.edu, bwmott@unity.ncsu.edu writes:
  18. >
  19. >I've got a question about forward declaring a class as a sub-class of
  20. >another class.  Is it possible under the C++ draft standard to do
  21. >something like:
  22. >
  23. >  class S;
  24. >  class T : public S;
  25.  
  26. No, for several reasons.
  27.  
  28. You cannot mention class internals until the definition of the class has
  29. been seen. You could otherwise in principle add things to a class
  30. without modifying the class definition. (Some languages allow you to
  31. do so, but C++ does not.)
  32.  
  33. Knowing only that T is derived from S is not any more helpful than knowing
  34. only that T is a class.  For example, casting a T* to an S* or the reverse
  35. in general requires the full class definitions.
  36.  
  37. Your example involved covariant return types. The compiler can't generate
  38. the appropriate pointer adjustments without seeing the class definitions.
  39. ---
  40. Steve Clamage, stephen.clamage@eng.sun.com
  41. ---
  42. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  43.   Contact address: std-c++-request@ncar.ucar.edu.  Moderation policy:
  44.   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
  45.